using Engine;
using Game;

namespace SCIENEW.Tech {
    /// <summary>
    /// 科技树节点
    /// </summary>
    public class TechNode {
        public enum Mode {
            Locked,
            Unlocked,
            Handling
        }

        public string Name { get; }
        public List<TechNode> Dependencies { get; private set; }

        #region 属性
        public string DisplayName { get; set; }
        public string Description { get; set; }
        public int IconBlock { get; set; }
        public bool IsLocked { get; set; }
        public List<BlockDropValue> Rewards { get; set; }
        public int Stage { get; set; }
        public Vector2 LayoutOffset { get; set; }
        #endregion

        public TechNode(string name) {
            Name = name;
            Dependencies = new List<TechNode>();
            IsLocked = true;
            Rewards = new List<BlockDropValue>();
            Stage = 0;
        }

        public void AddDependency(TechNode node) {
            Dependencies.Add(node);
        }

        /// <summary>
        /// 获得该节点状态
        /// 自己与依赖全锁了，锁定
        /// 自己锁了，依赖有一项没锁，进行中
        /// 自己没锁，解锁
        /// </summary>
        /// <returns></returns>
        public Mode GetMode() {
            if (IsLocked && Dependencies.All(x => x.IsLocked) && Dependencies.Count > 0) return Mode.Locked;
            if (IsLocked && (Dependencies.Any(x => !x.IsLocked) || Dependencies.Count == 0)) return Mode.Handling;
            if (!IsLocked) return Mode.Unlocked;
            return Mode.Locked;
        }
    }
}